package com.kt.game1

import java.awt.Color
import java.awt.Dimension
import java.awt.Font
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import javax.swing.JFrame
import javax.swing.JLabel

class Game0 : JFrame() {
    private val label = JLabel()
    private var snake = listOf(Pair(5, 5))
    private var food = Pair(10, 10)
    private var direction = "R"
    private var gameOver = false

    init {
        defaultCloseOperation = JFrame.EXIT_ON_CLOSE
        setSize(400, 400)
        title = "Snake Game"
        add(label)
        label.preferredSize = Dimension(400, 400)
        label.font = Font("Arial", Font.BOLD, 20)
        label.foreground = Color.BLACK
        addKeyListener(object : KeyAdapter() {
            override fun keyPressed(e: KeyEvent?) {
                if (e != null && !gameOver) {
                    when (e.keyCode) {
                        KeyEvent.VK_UP -> direction = "U"
                        KeyEvent.VK_DOWN -> direction = "D"
                        KeyEvent.VK_LEFT -> direction = "L"
                        KeyEvent.VK_RIGHT -> direction = "R"
                    }
                }
            }
        })
        isVisible = true
        gameLoop()
    }

    private fun gameLoop() {
        while (!gameOver) {
            moveSnake()
            checkCollision()
            repaint()
            Thread.sleep(200)
        }
    }

    private fun moveSnake() {
        // Logic to move the snake based on current direction
        // Update snake position and check for collision with food or itself
    }

    private fun checkCollision() {
        // Check for collisions with walls, food, or itself
    }

    override fun paint(g: java.awt.Graphics?) {
        super.paint(g)
        // Draw snake and food
    }
}

fun main() {
    Game0()
}